package com.ipkiss.incomespringboot.controller;

import com.ipkiss.incomespringboot.common.Constants;
import com.ipkiss.incomespringboot.common.Result;
import com.ipkiss.incomespringboot.model.param.UserParam;
import com.ipkiss.incomespringboot.service.impl.UserInfoService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author WuYongheng
 * @date 2024/5/11
 * @describe
 */
@RestController
@Slf4j
@RequestMapping("/user")
public class UsersController {
    @Resource
    UserInfoService userInfoService;

    /**
     * 用户登录的接口
     * 用户名和密码都，则正确返回成功的状态码、消息、用户数据
     *
     * @param param 用户名、密码
     * @return Result
     */
    @PostMapping("/v1/login")
    public Result<Integer> login(@RequestBody UserParam param) {
        log.info("User Login : {}", param.getUsername());
        int code = userInfoService.login(param);
        if (code == Constants.SUCCESS_CODE) {
            return Result.success(Constants.SUCCESS_LOGIN_CN, null);
        }
        return Result.error(Constants.FAILED_LOGIN_CN);
    }
}
